<?php
namespace app\api\controller\article;
use app\api\controller\Init;

class Banner extends Init
{
    public function initialize() {
        parent::initialize();
        $this->service = model('article/Banner', 'service');
    }

    /**
     * 获取导航栏列表
     * @return array
     *
     * @author <xiachao>
     * @date   2018/11/19 15:12
     */
    public function lists()
    {
        $field = $this->request->param('field/s',true);
        $relations = array_filter($this->request->param('relations/a',[]));
        $attrs = array_filter($this->request->param('attrs/a',[]));
        $maps = [];
        $maps['site_id'] = $this->site['id'];
        $maps['current_id'] = $this->site['custom_id'];
        $maps['status'] = 1;
        if ($this->request->has('keywords', 'param', true)) {
            $maps['title'] = $this->request->param('keywords/s', '');
        }
        $result = $this->service->lists($maps,'sort asc',$this->page,$this->limit,$field,$relations,$attrs);
        return $this->response("success", $result);
    }

    /**
     * 获取导航栏详情
     * @return array
     *
     * @author <xiachao>
     * @date   2018/11/19 18:42
     */
    public function detail() {
        $maps = [];
        if ($this->request->param('id/d') < 1){
            return $this->response('导航栏信息不能为空', [], -100002);
        }
        $maps['id'] = $this->request->param('id/d',0);
        $field = $this->request->param('field/s',true);
        $relations = array_filter($this->request->post('relations/a',[]));
        $attrs = array_filter($this->request->post('attrs/a',[]));
        $maps['site_id'] = $this->site['id'];
        $maps['current_id'] = $this->site['custom_id'];
        $maps['status'] = 1;
        $result = $this->service->detail($maps,true,$relations,$attrs);
        if (!$result) {
            return $this->response($this->service->getError(),[],-100003);
        }
        return $this->response("success", $result);
    }

}